﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using School.Entities;
using System.Collections;
using System.IO;


namespace School.Admission
{
    public class TransferRequestXSchools
    {
        private static SchoolEntities db = new SchoolEntities();

        public static Boolean Add( SD_Transfer_Request_Schools  transferrequestschools )
        {


            db.AddToSD_Transfer_Request_Schools(transferrequestschools);
            db.SaveChanges();
            return true;

        }

        public static SD_Transfer_Request_Schools Single(long id)
        {
            return db.SD_Transfer_Request_Schools.Single(x => x.Id == id);
        }


        public static IEnumerable<SD_Transfer_Request_Schools> All(Hashtable items)
        {
            SchoolEntities db = new SchoolEntities();

            var query = from transferrequestschools in db.SD_Transfer_Request_Schools select transferrequestschools;
            foreach (DictionaryEntry item in items)
            {
                if (item.Key == "SchoolName")
                {
                    query = query.Where(c => c.SchoolName == item.Value);
                }
            }
            return query.ToList();
        }

        public static void Update(SD_Transfer_Request_Schools transferrequestschools)
        {
            SD_Transfer_Request_Schools c = db.SD_Transfer_Request_Schools.Single(x => x.Id == transferrequestschools.Id);
            c.Id = transferrequestschools.Id;
            c.TransferRequestId = transferrequestschools.TransferRequestId;
            c.SchoolName = transferrequestschools.SchoolName;
            c.SatrtDate = transferrequestschools.SatrtDate;
            c.EndDate = transferrequestschools.EndDate;
            c.Address = transferrequestschools.Address;
            c.Certification = transferrequestschools.Certification;
            c.Grade = transferrequestschools.Grade;
            c.Stage = transferrequestschools.Stage;
            c.FirstLanguage = transferrequestschools.FirstLanguage;
            c.SecondLanguage = transferrequestschools.SecondLanguage;

            db.SaveChanges();

        }

        public static Boolean Delete(long id)
        {
            try
            {
                db.SD_Transfer_Request_Schools.DeleteObject(db.SD_Transfer_Request_Schools.Single(x => x.Id == id));
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

    }
}
